﻿Imports Microsoft.Win32

Public Class ConfigSettings
    Private Const ApplicationTitle As String = "Capture It"
    Public Enum CaptureType
        Rectangle = 0
        FullScreen = 1
        SelectedWindow = 2
    End Enum
    Public Shared Sub SaveSettings(ByVal currentSettings As Settings)
        Dim currentValue As String = [Enum].Parse(GetType(CaptureType), currentSettings.OptionType)
        Dim rootKey As RegistryKey = Registry.CurrentUser.CreateSubKey("Software")
        Dim AppNameKey As RegistryKey = rootKey.CreateSubKey(ApplicationTitle)
        Dim settingsKey As RegistryKey = AppNameKey.CreateSubKey("Settings")
        settingsKey.SetValue("CurrentUser", Environment.UserName)
        settingsKey.SetValue("Option", currentValue)
        settingsKey.Close()
        AppNameKey.Close()
        rootKey.Close()
    End Sub
    Public Shared Function ReadSettings() As Settings
        Dim currentSettings As New Settings
        currentSettings.OptionType = CaptureType.Rectangle
        Dim rootKey As RegistryKey = Registry.CurrentUser.CreateSubKey("Software")
        Dim AppNameKey As RegistryKey = rootKey.CreateSubKey(ApplicationTitle)
        If AppNameKey.GetSubKeyNames.Length >= 1 Then
            Dim settingsKey As RegistryKey = AppNameKey.CreateSubKey("Settings")
            settingsKey.SetValue("CurrentUser", Environment.UserName)
            currentSettings.OptionType = [Enum].Parse(GetType(CaptureType), settingsKey.GetValue("Option"))
            settingsKey.Close()
            AppNameKey.Close()
        End If
        rootKey.Close()
        Return currentSettings
    End Function
End Class
